<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>

<jsp:directive.include file="/controleDeAcesso/autenticado.jsp" />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Biblioteca Pessoal</title>
</head>
<body>
<f:view>
<h2>Biblioteca Pessoal de <h:outputText value="#{principal.usuario.nome}"></h:outputText>
</h2>
		<h:form>
			<h:commandLink action="cadastrarLivro">
				<h:outputText value="(+) Castrar um novo livro na sua biblioteca"></h:outputText>
			</h:commandLink>
		</h:form>
		<h:dataTable border="1" value="#{principal.usuario.listaLivros}" var="livro">
			<h:column id="column1">
				<f:facet name="header">
					<h:outputText value="Título"></h:outputText>
				</f:facet>
				<h:outputText value="#{livro.titulo}"></h:outputText>
			</h:column>
			<h:column id="column2">
				<f:facet name="header">
					<h:outputText value="Autor"></h:outputText>
				</f:facet>
				<h:outputText value="#{livro.autor}"></h:outputText>
			</h:column>
			<h:column id="column3">
				<f:facet name="header">
					<h:outputText value="Editora"></h:outputText>
				</f:facet>
				<h:outputText value="#{livro.editora}"></h:outputText>
			</h:column>
			<h:column id="column4">
				<f:facet name="header">
					<h:outputText value="Ano"></h:outputText>
				</f:facet>
				<h:outputText value="#{livro.anoPublicacao}"></h:outputText>
			</h:column>
			<h:column id="column5" >
				<f:facet name="header">
					<h:outputText value="Ações"></h:outputText>
				</f:facet>
				Editar | Remover
			</h:column>
			<h:column id="column6">
				<f:facet name="header">
					<h:outputText value="Emprestar"></h:outputText>
				</f:facet>
				<h:form>
					<h:outputText value="Emprestado para #{livro.emprestimo.responsavel}, em #{livro.emprestimo.data} " 
						rendered="#{livro.emprestado}"></h:outputText>
					<h:commandButton value="Devolver" rendered="#{livro.emprestado}" action="#{principal.devolverLivro}">
						<f:setPropertyActionListener value="#{livro.isnb}" target="#{principal.isbnDevolver}"/>
					</h:commandButton>
					<h:commandButton value="Emprestar" rendered="#{livro.notEmprestado}" action="emprestar">
						<f:setPropertyActionListener value="#{livro.isnb}" target="#{principal.isbnEmprestar}"/>
					</h:commandButton>
				</h:form>
			</h:column>
		</h:dataTable>
		
	<h:form>
			<h:commandButton value="Logout" action="#{principal.logout}" ></h:commandButton>
		</h:form>
	</f:view>
</body>
</html>